<%-- 
    Document   : PlaceList
    Created on : Jul 28, 2013, 8:42:18 AM
    Author     : SQL
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="stylesheet.css">
        <link rel="stylesheet" href="css/base.css">
        <link rel="stylesheet" href="css/themes/type_04.css">
        <link rel="stylesheet" href="css/themes/color_13.css">
        <title>Places to go to</title>
        <script>
            // create XML
            function createXMLonServer() {
                var request = new XMLHttpRequest();
                request.open("GET", "Place?province=${param.province}", false);
                request.send();                
            }

            function loadXMLDoc(dname)
            {
                var xhttp;
                if (window.ActiveXObject)
                {
                    xhttp=new ActiveXObject("Msxml2.XMLHTTP.3.0");
                }
                else
                {
                    xhttp=new XMLHttpRequest();
                }
                xhttp.open("GET",dname,false);
                xhttp.send("");
                if (xhttp.status === 200 || xhttp.status === 304) {
                    var xmlDoc = xhttp.responseXML;
                    return xmlDoc;
                } else {
                    createXMLonServer();
                    xmlDoc=loadXMLDoc(dname);
                    return xmlDoc;
                }                
            }
            
            function displayResult() {
                var realpath = '${pageContext.request.contextPath}';
                var xml = loadXMLDoc(realpath + "/ListPlaces${param.province}.xml");
                var xsl = loadXMLDoc(realpath + "/ListPlaces_CustomerStyleSheet.xsl");
                
                var result = new XSLTProcessor();
                result.importStylesheet(xsl);
                var resultDocument = result.transformToFragment(xml,document);
                document.getElementById("example").appendChild(resultDocument);
            } 
        </script>
    </head>
    <body onload="displayResult()">
    <header class="sixteen columns">
        <div id="logo">
            <h1>Bui travel</h1>
        </div>
        <hr />
        <form action="ListPlaceSearch" method="POST" id="searchFrom">
            <input type="hidden" name="txtXMLFile" value="ListPlaces${param.province}.xml"/>
            <input type="hidden" name="txtResultFile" value="SearchPlaces${param.province}.xml"/>
            <input type="text" name="txtSearch" value="" placeholder="Search" style="position:fixed; width: 150px;" size="35"/>            
        </form>      
        <br/>
        <br/>
        <form action="AddPlace.jsp" method="GET">
            <input type="hidden" value="${param.province}" name="province" />
            <input type="submit" value="Add a new place" style="position: fixed" />
        </form>
    </header>
    <div id="example"/>    
</body>
</html>
